using UnityEngine;

namespace GameCore
{
    public class DragItemState : PlayerInputState
    {
        public DraggableObject draggable;
        public Vector3 dragOffset;

        public DragItemState(DraggableObject draggable)
        {
            this.draggable = draggable;
            var mousePos = PlayerInputHandler.GetMouseWorldPosition();
            dragOffset = mousePos - draggable.transform.position;
            draggable.GetComponent<ObjectSorter>()?.SetTop();
        }
        
        public override void Update()
        {
            var mousePos = PlayerInputHandler.GetMouseWorldPosition();
            if (draggable is null) return;
            draggable.transform.position = mousePos - dragOffset;
        }
    }
}